﻿using FirstFloor.ModernUI.Windows.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Vtron.LEDCorrective.Core;
using Vtron.LEDCorrective.Domain.LEDSender;

namespace Vtron.LEDCorrective.Pages
{
    /// <summary>
    /// SplitScreen.xaml 的交互逻辑
    /// </summary>
    public partial class SplitScreen : UserControl
    {
        public SplitScreen()
        {
            InitializeComponent();

            Loaded += SplitScreen_Loaded;
        }

        private void SplitScreen_Loaded(object sender, RoutedEventArgs e)
        {
            column_txt.Text = 192.ToString();
            row_txt.Text = 192.ToString();
        }

        private void splitScreen_btn_Click(object sender, RoutedEventArgs e)
        {
            int column = 0;
            int row = 0;
            if (!Int32.TryParse(column_txt.Text, out column))
            {
                ModernDialog.ShowMessage("单分屏内像素列数必须为正整数，请重新输入！", "提示", MessageBoxButton.OK);
                return;
            }
            else if (column == 0)
            {
                ModernDialog.ShowMessage("单分屏内像素列数必须大于0，请重新输入！", "提示", MessageBoxButton.OK);
                return;
            }
            if (!Int32.TryParse(row_txt.Text, out row))
            {
                ModernDialog.ShowMessage("单分屏内像素行数必须为正整数，请重新输入！", "提示", MessageBoxButton.OK);
                return;
            }
            else if (row == 0)
            {
                ModernDialog.ShowMessage("单分屏内像素行数必须大于0，请重新输入！", "提示", MessageBoxButton.OK);
                return;
            }

            CorrectiveEngine correctiveEngine = CorrectiveEngine.Instance;
            SCP_WALLS_T wall = correctiveEngine.GetWall();

            if (wall.wallNum == 1)
            {
                correctiveEngine.ResolWidth = (int)wall.wall[0].resol.width;
                correctiveEngine.ResolHeight = (int)wall.wall[0].resol.height;
                correctiveEngine.ScaleColumn = (int)wall.wall[0].scale.col;
                correctiveEngine.ScaleRow = (int)wall.wall[0].scale.row;
                correctiveEngine.SplitScreenColumn = column;
                correctiveEngine.SplitScreenRow = row;

                correctiveEngine.Scp_wall = wall.wall[0];

                correctiveEngine.SplitScreenLedCollections.Clear();
                for (int i = 0; i < correctiveEngine.SplitScreenCount; i++)
                {
                    LEDCollection ledCollection = new LEDCollection(column, row);
                    correctiveEngine.SplitScreenLedCollections.Add(ledCollection);
                }

                ModernDialog.ShowMessage("分屏划分成功！", "信息", MessageBoxButton.OK);
            }
            else if (wall.wallNum == 0)
            {
                ModernDialog.ShowMessage("未分配默认墙体，请分配后再校正！", "提示", MessageBoxButton.OK);
                return;
            }
            else if (wall.wallNum > 1)
            {
                ModernDialog.ShowMessage("系统错误，默认墙体大于一个！", "错误", MessageBoxButton.OK);
                return;
            }
        }
    }
}
